package cn.schoolwow.util.module.check.jsonarray.flow.check;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import com.alibaba.fastjson.JSONArray;

public class CheckJSONArrayNotNullFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String fieldName = (String) flowContext.checkData("fieldName");
        JSONArray array = (JSONArray) flowContext.checkData("array");
        String message = (String) flowContext.checkData("message");

        for(int i=0;i<array.size();i++){
            Object fieldValue = array.getJSONObject(i).get(fieldName);
            if(null==fieldValue){
                throw new IllegalArgumentException(message+"不能为空");
            }
        }
    }

    @Override
    public String name() {
        return "实例列表-检查NULL字段";
    }
}
